// pages/route2/order/order.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('onLoad')
    console.log(options)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  toorder(){
    var that=this;
    console.log(that.data.order)
    wx.request({
      url: app.globalData.orderUrl + '/api/s/orders/create/',
      method: 'GET',
      data: {
        "session": wx.getStorageSync('session'),
        'orderId': that.data.order.orderId ,
        items: { 'items': that.data.order.items },
      },
      header: {
        'content-type': "application/x-www-form-urlencoded",
      },
      success: function (res) {
        if (res.data.status == 4201) {
          console.log(res.data.data[0].onerror)
          var minip = res.data.data[0].onerror.params
          wx.navigateToMiniProgram({
            appId: minip.appid,
            path: minip.path + '?session=' + wx.getStorageSync('session') + '&orderId=' + that.data.order.orderId +'&back=' + minip.data.back,
            extraData: {
              back: minip.data.back,
              session: wx.getStorageSync('session'),
              orderId: that.data.order.orderId
            },
            envVersion: minip.version,
            success(res) {
              // 打开成功
            }
          })
        }
      }
    })
  },
  // preorder: function () {
  //   var that = this
  //   var items = []
  //   var item = {}
  //   for (let item2 of this.data.list) {
  //     if (item2.status == true) {
  //       item.productId = item2.proobj.productId
  //       item.qty = item2.pronum
  //       items.push(item)
  //       item = {}
  //     }
  //   }
  //   wx.request({
  //     url: 'https://test.mine.api.logic.alorvalley.com/api/s/orders/create/',
  //     method: 'GET',
  //     data: {
  //       "session": wx.getStorageSync('session'),
  //       'orderId': '',
  //       items: { 'items': items },
  //     },
  //     header: {
  //       'content-type': "application/x-www-form-urlencoded",
  //     },
  //     success: function (res) {
  //       if (res.data.status == 200) {
  //         wx.setStorageSync('order', res.data.data[0])
  //         that.setData({
  //           order: wx.getStorageSync('order')
  //         })
  //       }
  //     }
  //   })
  // },
  onShow: function (options) {
    app.userLogin()
    console.log('options')
    console.log(options)
    var repro = wx.getStorageSync('order')
    this.setData({
      order: repro
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  onShareAppMessage: function () {
    return {
      title: '十里芳菲',
      path: 'pages/route2/index/index'
    }
  }
})